/**
 * @file Define controller base class for all controllers
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */

const EventEmitter = require('events');

/**
 * The base controller class
 * 
 * @class BaseController
 * @extends {EventEmitter}
 */
class BaseController extends EventEmitter {

    /**
     * Get system service
     * 
     * @name getSystemService
     * @param {String} serviceName - The service name
     * 
     * @returns {SystemService}
     */
    getSystemService(serviceName) {
        return this.Context.getSystemService(serviceName);
    }

    get name() {
        return 'base';
    }

    get handlersPath() {
        return 'base';
    }

    get Context() {
        if (!this._context) {
            this._context = this.Application.Context;
        }
        return this._context;
    }

    get Application() {
        return this._Application;
    }

    get ControllerConfig() {
        return this.Application.getConfiguration(Configuration.WEB_CONTROLLER);
    }

    get Server() {
        return this._Server;
    }

    constructor(application, server) {
        super();
        this._Application = application;
        this._Server = server;
        this.loadHandlers();
    }

    /**
     * Load controler's handlers classes into controller
     * 
     * @name loadHandlers
     * 
     * @returns {void}
     */
    loadHandlers() {}
}

module.exports = BaseController;